package cn.kgc.bdqn_studentinfomanager.controller;

/**
 * by Shanshui CC on 2020/12/10 11:42
 */

import cn.kgc.bdqn_studentinfomanager.pojo.common.ServerResponse;
import cn.kgc.bdqn_studentinfomanager.pojo.vo.AddUserVo;
import cn.kgc.bdqn_studentinfomanager.service.CommService.CommService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 渠道专员模块
 */
@RestController
@RequestMapping("/commissioner")
@CrossOrigin
public class CommController {

    @Resource
    private CommService commService;

    /**
     * 进入添加专员页面时加载地区下拉框
     * @param request
     * @return
     */
    @RequestMapping("/loadingCommAddress")
    public ServerResponse loadingCommAddress(HttpServletRequest request, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Cache-Control","no-cache");

        return commService.loadingCommAddress(request.getHeader("token"));
    }

    /**
     * 渠道主管添加渠道专员
     * @param addUserVo
     * @param request
     * @return
     */
    @RequestMapping(value = "/addcommissioner", method = RequestMethod.POST)
    public ServerResponse addcommissioner(AddUserVo addUserVo, HttpServletRequest request,HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Cache-Control","no-cache");

        return commService.addcommissioner(addUserVo,request.getHeader("token"));
    }


    /**
     *  初始化咨询师
     * @return
     */
    @RequestMapping("/loadingConInfo")
    public ServerResponse loadingConInfo(HttpServletResponse response){
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Cache-Control","no-cache");

        return commService.loadingConInfo();
    }


    /**
     * 分配咨询师
     * @param
     * @return
     */
    @RequestMapping("/distributionStudent")
    public ServerResponse distributionStudent(String studentId, String conId){

        List<String> studentItList = new ArrayList<>();
        String[] split = studentId.split(",");
        for (int i = 0; i < split.length; i++) {
            studentItList.add(split[i]);
        }

        return commService.distributionStudent(studentItList,conId);
    }

}
